package com.cmx.controller;

import com.cmx.dao.UserMapper;
import com.cmx.model.User;
import com.cmx.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created by cmx on 2017/5/12.
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired private UserService userService;
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @ExceptionHandler
    public void exceptionHandler(Exception e ){

    }

    @RequestMapping(value = "/get_user", method= RequestMethod.GET)
    public ResponseEntity getUserById(Integer uid){

        User user = userService.selectUser(uid);
        return new ResponseEntity<User>(user,HttpStatus.OK);

    }
    @RequestMapping(value = "/get_user1" , method=RequestMethod.GET)
    public User getUser1(User user){
         User user1  = userService.selectUser(user.getUid());
        return  user1;
    }
    @RequestMapping(value = "/update_user",method = RequestMethod.POST)
    public ResponseEntity updateUser(User user){
        userService.updateUser(user);
        return new ResponseEntity(1,HttpStatus.OK);
    }
    @RequestMapping(value = "create_user",method = RequestMethod.POST)
    public ResponseEntity createUser(User user) {
        userService.insertUser(user);
        return new ResponseEntity(1,HttpStatus.OK);
    }


}
